package com.epro.dx.task;

import java.util.ArrayList;

import com.epro.dx.listenner.MyAsyncTaskListenner;
import com.epro.dx.util.ActivityUtil;
import com.weipu.common.constants.ServerConstant;
import com.weipu.common.facade.exception.DxException;
import com.weipu.common.facade.factory.ProviderFactory;
import com.weipu.common.util.StringUtil;

import android.os.AsyncTask;
/************************
 * @author Tony
 * @Date:2016-5-11上午10:11:43
 * @描述:获取用户是否有未读消息
 ************************/
public class GetIsNotReadAsyncTask extends AsyncTask<Void,Void,String> {

	private MyAsyncTaskListenner myAsyncTaskListenner;
	private boolean isNotRead;
	public GetIsNotReadAsyncTask(MyAsyncTaskListenner myAsyncTaskListenner){
		this.myAsyncTaskListenner = myAsyncTaskListenner;
	}
	@Override
	protected void onPreExecute() {
		if(null!=myAsyncTaskListenner){
			myAsyncTaskListenner.onPreTask();
		}
		super.onPreExecute();
	}
	@Override
	protected String doInBackground(Void... params) {
		try {
			isNotRead = ProviderFactory.createMessageService().getIsNotRead(ActivityUtil.getCustomerID());
		} catch (DxException e) {
			return e.getErrCode();
		}
		return "0";
	}
	@Override
	protected void onPostExecute(String result) {
		if(null!=myAsyncTaskListenner){
			myAsyncTaskListenner.onPostTask(result, isNotRead);
		}
		if("0".equals(result)){
			StringUtil.saveConfig(ServerConstant.MessageCenter.UNREAD_MESSAGE, String.valueOf(isNotRead));
		}
		super.onPostExecute(result);
	}

}
